package com.jishuo.nontax.api.socket.handle;

import com.jishuo.base.bean.BaseResult;
import com.jishuo.base.util.SpringContextUtil;
import com.jishuo.nontax.api.socket.ApiHandle;
import com.jishuo.nontax.bfc.service.ItemService;
import com.jishuo.nontax.bfc.service.UnitVsItemService;
import org.dom4j.Element;

/**
 * @author hlp
 * @date 2023/2/8 15:16
 * @Description:
 */
public class ItemApi implements ApiHandle {
    @Override
    public BaseResult execute(String head, Element body) {
        if (head.equals("selItem")) { //根据项目编号查询预算单位可用的收费项目
            String itemcode = body.selectSingleNode("//root/body/itemcode").getText();

            ItemService itemService = (ItemService) SpringContextUtil.getBean("itemService");
            return itemService.selNewItem(itemcode);

        }else if(head.equals("findUnitVsItem")){ //查询预算单位可用的收费项目
            String unitid = body.selectSingleNode("//root/body/unitid").getText();
            ItemService itemService = (ItemService) SpringContextUtil.getBean("itemService");

            return itemService.findUnitVsItem(Long.valueOf(unitid));
        }else if(head.equals("selUnitVsItem")){ //根据单位唯一标识查询单位标识,项目标识,编号
            String unitid = body.selectSingleNode("//root/body/unitid").getText();
            UnitVsItemService unitVsItemService = (UnitVsItemService) SpringContextUtil.getBean("unitVsItemService");
            return unitVsItemService.selUnitVsItem(Integer.parseInt(unitid));
        }
        return null;
    }
}
